package com.zmn.oms.dubbo.impl.zmn.normal.work;


import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.ResponseDTO;
import com.zmn.common.utils.response.ResponseUtil;
import com.zmn.oms.dubbo.impl.OmsBaseRemoteService;
import com.zmn.oms.dubbo.interfaces.zmn.normal.work.ZsNormalWorkRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.services.interfaces.datasync.ElasticSearchDataSyncService;
import com.zmn.oms.services.interfaces.order.OrderChangeService;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;

/**
 * 类描述：普通工单服务
 *
 * @author heciqi
 * @date 2018/11/21 19:37
 */
@Service(loadbalance = "roundrobin", timeout = 5000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class ZsNormalWorkRemoteServiceImpl extends OmsBaseRemoteService implements ZsNormalWorkRemoteService {

    private static final String TAG = "啄木鸟-普通工单-工单修改dubbo接口";

    @Autowired
    private OrderWorkService orderWorkService;
    @Autowired
    OrderChangeService orderChangeService;
    @Autowired
    ElasticSearchDataSyncService elasticSearchDataSyncService;

    @Override
    public ResponseDTO updateOrderChannelSettleStatus(Long orderId, Long workId, Integer status) {
        if (Objects.isNull(orderId) || Objects.isNull(workId)) {
            logger.error("[{}]参数：orderId={}，workId={} 不能为空", TAG, orderId, workId);
            return ResponseUtil.responseFail("工单ID/订单ID不能为空");
        }
        OrderWork orderWork = new OrderWork();
        orderWork.setOrderId(orderId);
        orderWork.setWorkId(workId);
        orderWork.setComplaintStatus(GlobalConsts.YES);
        orderWorkService.updateOrderChannelSettleStatus(orderWork);
        return ResponseUtil.responseSuccess();
    }

    /**
     * 渠道结算
     * @param orderIds
     * @return
     */
    @Override
    public ResponseDTO updateOrderChannelSettleStatus(List<Long> orderIds) {
        if (CollectionUtils.isEmpty(orderIds)){
            return ResponseUtil.responseFail("工单ID/订单ID不能为空");
        }
        elasticSearchDataSyncService.syncWorkIndex(orderIds);
        return ResponseUtil.responseSuccess();
    }

}
